<template>
    <a-row id="globalHeader" align="center" :wrap="false">

      <!--<a-col flex="100px">-->
      <!--  <div>100px</div>-->
      <!--</a-col>-->
      <a-col flex="auto">
        <a-menu mode="horizontal"
                :selected-keys="selectedKeys"
                @menu-item-click="doMenuClick"
        >
          <a-menu-item key="0" :style="{ padding: 0, marginRight: '38px' }" disabled>
            <div class="title-bar">
              <img class="logo" src="../assets/ojlogo.jpg">
              <div class="title">OJ System~</div>
            </div>
          </a-menu-item>
          <a-menu-item v-for="item in visibleRoutes" :key="item.path">
            {{ item.name }}
          </a-menu-item>

        </a-menu>
      </a-col>

      <a-col flex="100px">
        <div>
          {{ store.state.user?.loginUser?.userName ?? '未登录'}}
          <!--wsy-->
        </div>
      </a-col>
    </a-row>
</template>

<script setup lang="ts">
import {routes} from '../router/routes'
import {useRoute, useRouter} from "vue-router";
import { computed,ref } from "vue";
import {useStore} from "vuex";
import checkAccess from "@/access/checkAccess";
import accessEnum from "@/access/accessEnum";

//默认主页
const selectedKeys = ref(["/"])
const router = useRouter();
const store = useStore();
const loginUser = store.state.user.loginUser


//展示的路由
// const visibleRoutes = routes.filter((item, index) => {
//   return !item.meta?.hideInMenu && checkAccess(loginUser, item?.meta?.access as string)
// })
const visibleRoutes = computed(() => {
  return routes.filter((item, index) => {
    return !item.meta?.hideInMenu &&
        checkAccess(store.state.user.loginUser, item?.meta?.access as string)
  })
})

//路由跳转后，更新菜单项
router.afterEach(((to) => {
  selectedKeys.value = [to.path];
}))

const doMenuClick = (key: string) => {
  router.push({
    path: key
  })
}

// setTimeout(() => {
//   store.dispatch("user/getLoginUser", {
//     userName: "拍拍熊",
//     userRole: accessEnum.ADMIN
//   })
// }, 3000);


</script>

<style scoped>
.title-bar {
  align-items: center;
  display: flex;
}

.title {
  color: #42b983;
  margin-left: 16px;
}

.logo {
  height: 48px;
}
</style>